<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>新增供应商账号</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
	<form id="formSet1">
		<div class="fieldset1 tabel_col clearFix">
			<div class="fieldBox col_50">
				<div class="label">账号类型</div>
				<div class="field">
					<select name="bizTypCd" id="bizTypCd" data-value=" " validate ="{required:true,select:true}">
						<option value=" " checked >请选择</option>
						<c:forEach items="${bizTypCdList }" var="kv">
							<option value="${kv.key }">${kv.value }</option>
						</c:forEach>
					</select>
					<span class="requiredSymbol">*</span>
				</div>
			</div>
			<div class="fieldBox col_50">
                <div class="label">收款方</div>
                <div class="field">
                	<input type="text" id="rcptUnt" name="rcptUnt" class="ui-textbox" validate ="{required:true}"/>
                	<span class="requiredSymbol">*</span>
                </div>
            </div>
			<div class="fieldBox col_50">
                <div class="label">收款账号</div>
                <div class="field">
                	<input type="text" id="accNo" name="accNo" class="ui-textbox" validate ="{required:true,number:true}"/>
                	<span class="requiredSymbol">*</span>
                </div>
            </div>
			<div class="fieldBox col_50">
                <div class="label">开户行</div>
                <div class="field">
                	<input type="text" id="bkNm" name="bkNm" class="ui-textbox" validate ="{required:true}"/>
                	<span class="requiredSymbol">*</span>
                </div>
            </div>
			<div class="fieldBox col_50">
                 <div class="label">开户行行号</div>
                 <div class="field">
                 	<input type="text" id="bkNo" name="bkNo" class="ui-textbox" validate ="{required:true,number:true}"/>
                 	<span class="requiredSymbol">*</span>
                 </div>
			</div>
			<div class="fieldBox col_50 isPrivate">
				<div class="label">银行预留手机号</div>
				<div class="field">
					<input type="text" id="bkResTel" name="bkResTel" class="ui-textbox" validate ="{number:true}"/>
					<span class="requiredSymbol">*</span>
				</div>
			</div>
			<div class="fieldBox col_50 isPrivate">
				<div class="label">收款方身份证号</div>
				<div class="field">
					<input type="text" id="certNo" name="certNo" class="ui-textbox"/>
					<span class="requiredSymbol">*</span>
				</div>
			</div>
			<div class="fieldBox col_50">
				<div class="label">联系方式</div>
				<div class="field">
					<input type="text" id="contTel" name="contTel" class="ui-textbox"/>
					<span id="contTelSpan" class="requiredSymbol" style="display: none">*</span>
				</div>
			</div>
			<div class="fieldBox col_66_auto">
                 <div class="label">区域</div>
                 <div class="field">
                 	<jsp:include page="../../system/sysRegion/region.jsp" flush="true" >
						<jsp:param name="regionShowLvl" value="2"/>
					</jsp:include>
                 </div>
			</div>
			<div class="fieldBox col_50">
				<div class="label">账户用途</div>
                    <div class="field">
                        <%-- <select name="purpCd" id="purpCd" data-value=" " validate ="{required:true,select:true}">
                        	<option value=" " checked >请选择</option>
							<c:forEach items="${purpCdList }" var="kv">
							    <option value="${kv.key }">${kv.value }</option>
							</c:forEach>
						</select> --%>
						<input type="text" id="purpCd" name="purpCd" validate="{required:true}" onchange="purpCdChange();" ltype="combobox"/>
						<span class="requiredSymbol">*</span>
                    </div>
			</div>
			<div class="fieldBox col_100">
				<div class="label">备注</div>
					<div class="field">
						<input type="text" id="bkRem" name="bkRem" class="ui-textbox" />
					</div>
			</div>
			<c:if test="${isFlow==1 }">
                <div class="fieldBox col_100">
                    <div class="label">供应商</div>
                    <div class="field">
                    	<a href="javascript:showSplDetail()" class="link">
                   			<span id="splNm" name="splNm">${splNm }</span>
                    	</a>
                    	<input name="splId" id="splId" type="hidden" value="${splId }">
                    </div>
                </div>
               </c:if>
			<div id="fileDIV" class="fieldBox col_100" id="fileModify">
				<div class="label">资料</div>
				<div class="field">
                	<jsp:include page="../../system/sysUlFilesRec/sysUlFileRecList.jsp" flush="true" >
                   		<jsp:param name="pkId" value="${id }"/>
                   		<jsp:param name="tabNm" value="SPL_BANK_ACC"/>
                 	</jsp:include>
            	</div>
			</div>
			<div id="fileUploadDIV" class="fieldBox col_100">
				<div class="label">资料上传</div>
				<div class="field">
                   	<jsp:include page="../../system/sysUlFilesRec/sysSysUlFilesRecUpload2.jsp" flush="true" >
                   		<jsp:param name="filePath" value="/splbank"/>
                   	</jsp:include>
				</div>
			</div>
			<div id="noticeDIV" class="fieldBox col_100">
				<div class="label">注:</div>
				<div class="field">
					<span name="" id="" style="color: red;">对公账号需上传企业营业执照.</span>
				</div>
			</div>
            <input name="bkId" id="bkId" type="hidden" value="${id }">
		</div>
		<div class="btnsBox">
            <c:if test="${isFlow==1 }">
            <!-- 供应商新增是弹出框 附加信息引用的时候没有保存按钮 所以在这里加一个 -->
	            <span id="saveBtn1" class="sq-button sq-button-round" onclick="save();">保存</span>
            </c:if>
        </div>
</form>
</div>


<script type="text/javascript">
	var _splId = '${splId}';
	var id = '${id}';
	var disable = '${disable}';
	var bizTypCd = '${bizTypCd}';
	$(function(){
		var _purpCdListJSON =  ${purpCdListJSON};
		$("#purpCd").ligerComboBox({ isShowCheckBox: true, isMultiSelect: true,
	        data: _purpCdListJSON,
	        valueField: 'key',
	        textField:'value',
	        onChangeValue :function(value){
	        }
	    });
		
		initData();
		if(id == ""){//新增
	    	$("#fileModify").remove();//移除资料DIV
	    }
		var formSet1 = $('#formSet1').ligerForm({
			validate : true
		});
		/* formSet1.setFieldValidate("rgnProvCd", {
	        required: true,
	        select: false
	    });
		formSet1.setFieldValidate("rgnCityCd", {
	        required: true,
	        select: false
	    }); */
	    if(disable==1){
	    	//禁用除用途字段
	    	disableFeild();
	    }
        bizTypCdChange();
	});
	//定义父级调用事件
	frameElement.dialog.onOk = function () {
	     save();
	}
	           
	frameElement.dialog.onCancel = function () {
	     frameElement.dialog.close();
	}
	
	//禁用除用途外字段  移除资料部分
	function disableFeild(){
		if(liger.get("rcptUnt")){
			liger.get("rcptUnt").setDisabled(true);
		}
		if(liger.get("accNo")){
			liger.get("accNo").setDisabled(true);
		}
		if(liger.get("bkNm")){
			liger.get("bkNm").setDisabled(true);
		}
		if(liger.get("bkNo")){
			liger.get("bkNo").setDisabled(true);
		}
		disabledRgnProvCd();//禁用区域
		disabledRgnCityCd();
		if(liger.get("bizTypCd")){
			liger.get("bizTypCd").setDisabled(true);
		}
		if(liger.get("bkRem")){
			liger.get("bkRem").setDisabled(true);
		}
		if(liger.get("contTel")){
			liger.get("contTel").setDisabled(true);
		}
		$("#fileDIV").remove();
		$("#fileUploadDIV").remove();
		$("#noticeDIV").remove();
		$(".isPrivate").remove();
	}
	
	function bizTypCdChange(){
        if(bizTypCd==0){
            //账号类型对公
            $("#noticeDIV").show();
            $(".isPrivate").css('display','none');
            $("#bkResTel").rules('remove','required')
            $("#certNo").rules('remove','required')
        }else{
            //账号类型对私
            $("#noticeDIV").hide();
            $(".isPrivate").css('display','block');
            $("#bkResTel").rules("add",{required:true})
            $("#certNo").rules("add",{required:true})
        }
        $("#bizTypCd").change(function(event) {
            bizTypCd = $("#bizTypCd").val();
            if(bizTypCd==0){
                //账号类型对公
                $("#noticeDIV").show();
                $(".isPrivate").css('display','none');
                $("#bkResTel").rules('remove','required')
                $("#certNo").rules('remove','required')
            }else{
                //账号类型对私
                $("#noticeDIV").hide();
                $(".isPrivate").css('display','block');
                $("#bkResTel").rules("add",{required:true})
                $("#certNo").rules("add",{required:true})
            }
        });
	}
	function save(){
		var form = liger.get("formSet1");
	    if (!form.valid()) {
	    	$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO , SQ_type: "warning" });
	        return false; //验证不通过，不执行以下代码
	    }
	    
	    var data = form.getData();
	    var id = $("#bkId").val();
	    data["splId"] = _splId;
	    var fileParams = getUploadResultParams();//获取附件上传的信息
	    data["fileParams"] = JSON.stringify(fileParams);
	    data["rgnPrCd"] = getRgnProvCd();//获取省代码
	    data["rgnCyCd"] = getRgnCityCd();//获取市代码
	    
	    var url = '<%=path%>/product/splBank/add.do';
	    if(id != ""){
	    	url = '<%=path%>/product/splBank/modify.do';
	    	data["id"]= id;
	    	data["disable"]= disable;
	    }
	    var wait_dialog;
	    $.ajax({
			type: 'post',
			dataType:'json',
			data:data,
			url: url,
			beforeSend: function(){
		          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
		     },
			success:function(msg){
				 wait_dialog.close();
				 if(msg.success == 1){
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
		             parent.callback();
		             frameElement.dialog.close();
				 }else{
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				 }
			}
		});
	}
	function initData(){
		var id = $("#bkId").val();
    	if(!id){
    		return;
    	}
    	var _url = '<%=path%>/product/splBank/getById.do';
    	$.ajax({
    		type: 'get',
    		dataType:'json',
    		data:{id:id},
    		url: _url,
    		success:function(msg){
    			 if(msg.success == 1){
    				 setData(msg.data);//设置数据
    			 }else{
    				 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
    			 }
    		}
    	});
   	}
		
	//设置页面数据
    function setData(data){
		//根据账号的审核状态设置字段是否可用
		var audStsCdNm = data.audStsCdNm;
		if(audStsCdNm==CommonConstant.C_AUD_ADNWAY_CODE||audStsCdNm==CommonConstant.C_AUD_PASS_CODE){
			//设置一些重要字段不可操作  setReadonly
			liger.get("rcptUnt").setDisabled();
			liger.get("accNo").setDisabled();
			liger.get("bkNm").setDisabled();
			liger.get("bkNo").setDisabled();
			liger.get("bizTypCd").setDisabled();
			liger.get("rgnProvCd").setDisabled();
			liger.get("rgnCityCd").setDisabled();
			liger.get("certNo").setDisabled();
			liger.get("bkResTel").setDisabled();
		}
    	var form = liger.get("formSet1");
    	form.setData({
    		bizTypCd:data.bizTypCd,
    	});
    	//区域数据处理
    	setRgnProvCdUpdataValue(data.rgnPrCd);
    	setRgnCityCdUpdataValue(data.rgnCyCd);
    	setRegionSelectDataChange();
    	
    	$("#rcptUnt").val(data.rcptUnt);
    	$("#accNo").val(data.accNo);
    	$("#bkNm").val(data.bkNm);
    	$("#bkNo").val(data.bkNo);
    	$("#bkRem").val(data.bkRem);
    	$("#contTel").val(data.contTel);
    	$("#certNo").val(data.certNo);
    	$("#bkResTel").val(data.bkResTel);

    	$("#purpCd").ligerGetComboBoxManager().selectValue(data.purpCd);
    	$("#purpCd").ligerGetComboBoxManager().updateStyle();
	};

	function showSplDetail(){
		var splId = $("#splId").val();
		if(StringUtils.isNotEmpty(splId)){
			Add_navTab('splInfo'+splId,'供应商详情','<%=path%>/product/splInfo/toDetailPage.do?id='+splId);
		}
	}

	var currOrgCd = '${currOrgCd}';
	function purpCdChange(){
		var orgcd = currOrgCd.substring(0,12);
		if(orgcd=="000000080002"){
			var purpCd = liger.get("purpCd").getValue();
			if(purpCd.indexOf(CommonConstant.C_SPL_PURP_CD_2)>-1){
				var formSet1=liger.get("formSet1");
				formSet1.setFieldValidate("contTel", {
			        required: true
			    });
				$("#contTelSpan").show();
			}else{
				var formSet1=liger.get("formSet1");
				formSet1.setFieldValidate("contTel", {
			        required: false
			    });
				$("#contTelSpan").hide();
			}
		}
	}
</script>



</body>
</html>
